package com.lucker.service.caipiao;

import java.text.DateFormat;
import java.text.ParseException;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSONObject;
import com.lucker.cds.model.CCaiPiao;
import com.lucker.cds.model.CEvenyDayOpenTime;
import com.lucker.common.enums.PushType;
import com.lucker.common.model.EntityHeader;
import com.lucker.common.model.PushEntity;
import com.lucker.common.util.CommonStr;
import com.lucker.common.util.DateTimeUtil;
import com.lucker.common.util.StringUtil;
import com.lucker.common.util.UUIDUtils;
import com.lucker.ds.mapper.BaseCustomMapper;
import com.lucker.ds.model.CaiPiao;
import com.lucker.ds.model.CaiPiaoErrorCode;
import com.lucker.ds.model.CaiPiaoOpenTime;
import com.lucker.ds.model.CaiPiaoOpencode;
import com.lucker.ds.model.EvenyDayOpenTime;
import com.lucker.ds.model.SysRestrictionsConfig;
import com.lucker.framework.constant.ResponseBaseModel;
import com.lucker.framework.constant.ResponseResultModel;
import com.lucker.framework.exception.BaseServiceException;
import com.lucker.service.BaseServiceImpl;
import com.lucker.service.caipiaoerrorcode.CaiPiaoErrorCodeService;
import com.lucker.service.caipiaomisscodelist.CaiPiaoMissCodeListService;
import com.lucker.service.caipiaosimulationplan.CaiPiaoSimulationPlanService;
import com.lucker.service.evenydayopentime.EvenyDayOpenTimeService;
import com.lucker.service.mail.MailService;
import com.lucker.service.model.Mail;
import com.lucker.service.push.socket.SocketService;
import com.lucker.service.sms.SmsService;
import com.lucker.service.sys.SysRestrictionsConfigService;

@Service
public class CaiPiaoServiceImpl extends BaseServiceImpl<CaiPiao, CCaiPiao, Long> implements CaiPiaoService {
	@Autowired 
	CaiTypeService caiTypeService;
	
	@Autowired
	CaiPiaoService caiPiaoService;
	
	@Autowired
	CaiPiaoOpencodeService caiPiaoOpencodeService;
	
	@Autowired
	CaiPiaoOpenTimeService  caiPiaoOpenTimeService;
	
	@Autowired
	SocketService  socketService;
	
	@Autowired
	EvenyDayOpenTimeService  evenyDayOpenTimeService;
	
	@Autowired
	SmsService smsService;
	
	@Autowired
	CaiPiaoErrorCodeService caiPiaoErrorCodeService;
	
	@Autowired
	MailService mailService;
	
	@Autowired
	SysRestrictionsConfigService sysRestrictionsConfigService;
	
	@Autowired
	CaiPiaoSimulationPlanService caiPiaoSimulationPlanService;
	
	@Autowired
	CaiPiaoMissCodeListService caiPiaoMissCodeListService;
	
	private ExecutorService	executorService	= Executors.newFixedThreadPool(10);
	
	
	@Override
	public BaseCustomMapper<CCaiPiao, Long> getCustomMapper() {
		return null;
	}
	
	public CaiPiao getCaiPiaoObjectByCaiId(int caiId) {
		
		CaiPiao _caipiao = new CaiPiao();
		_caipiao.setCaiId(caiId);
		List<CaiPiao> list = queryAll(_caipiao);
		
		if(CollectionUtils.isEmpty(list)) {
			throw new BaseServiceException("caiId:" + caiId + " 在CAIPIAO表中没有记录，请检查参数！");
		}
		if(list.size() > 1) {
			throw new BaseServiceException("caiId:" + caiId + " 在CAIPIAO表中有多条记录，请检查参数！");
		}
		return list.get(0);
	}
	
	
	
	
	@Transactional
	public void commitCaiPiao(int typeId,String openCode,String domainName,int domainId,String issueNo,String commit_time) {
		/***************/
		if(StringUtils.isBlank(issueNo)) {
			throw new BaseServiceException("提交开奖号码错误, 缺少开奖期数");
		}
		CaiPiao _cp = new CaiPiao();
		if(StringUtils.isNotBlank(domainName))_cp.setDomainName(domainName);
		//if(domainId > 0)_cp.setDomainId(String.valueOf(domainId));
		
		_cp.setCaiTypeId(String.valueOf(typeId));
		List<CaiPiao> _list = caiPiaoService.queryAll(_cp);
		if(CollectionUtils.isEmpty(_list)) {
			throw new BaseServiceException("该彩票种类不存在，" + domainName + "*" + domainId +  "或者该地区没有发行该彩种");
		}
		
		if(_list.size() > 1) {
			throw new BaseServiceException("该地区该彩种在数据库存在多条数据，请检查彩种");
		}
		CaiPiaoOpenTime queryCaiPiaoOpenTime = new CaiPiaoOpenTime();
		if(StringUtils.isNotBlank(domainName))queryCaiPiaoOpenTime.setDomainName(domainName);
		//if(domainId > 0)queryCaiPiaoOpenTime.setDomainId(Long.valueOf(domainId));
		String issueNoSuffix = "";
		if(issueNo.length() > 6) {
			issueNoSuffix = StringUtils.substring(issueNo, 6);
		}
		queryCaiPiaoOpenTime.setCaipiaoIssueno(issueNoSuffix);
		queryCaiPiaoOpenTime.setCaipiaoTypeId(String.valueOf(typeId));
		List<CaiPiaoOpenTime> _caiPiaoOpenTimeList = caiPiaoOpenTimeService.queryAll(queryCaiPiaoOpenTime);
		if(CollectionUtils.isEmpty(_caiPiaoOpenTimeList)) {
			throw new BaseServiceException("未维护该省份:"+domainName + "*" + domainId+"该彩种:"+typeId+"的开奖时间表,请联系系统管理员进行维护");
		}
		if(_caiPiaoOpenTimeList.size() > 1) {
			throw new BaseServiceException("该省份:"+domainName + "*" + domainId+"该彩种:"+typeId+"的    " +issueNo+ "  这期开奖时间表维护了一条以上的记录,请联系系统管理员进行维护");
		}
		String caipiaoOpenTimeStr = DateTimeUtil.getDate("YYYY-MM-dd") + " " + _caiPiaoOpenTimeList.get(0).getOpenTime();
		
		Date openCodeDateTime;
		try {
			openCodeDateTime = DateTimeUtil.getDateByString(caipiaoOpenTimeStr, "yyyy-MM-dd HH:mm:ss");
		} catch (ParseException e) {
			getLOGGER().error("日期格式转换出错  {}" , e);
			throw new BaseServiceException("开奖日期 " + caipiaoOpenTimeStr + "  格式转换出错");
		}
		long   caipiaoid = _list.get(0).getCaiId().longValue();
		String caipiaoName = _list.get(0).getCaiName();
		String caipiaoType = _list.get(0).getCaiTypeId();
		
		CaiPiaoOpencode queryCaiPiaoOpencode = new CaiPiaoOpencode();
		
		queryCaiPiaoOpencode.setIssueno(issueNo);
		queryCaiPiaoOpencode.setCaiTypeId(String.valueOf(typeId));
		queryCaiPiaoOpencode.setCaiId(String.valueOf(caipiaoid));
		List<CaiPiaoOpencode> _caiPiaoOpenCodeList = caiPiaoOpencodeService.queryAll(queryCaiPiaoOpencode);
		if(_caiPiaoOpenCodeList != null && _caiPiaoOpenCodeList.size() > 0) {
			//如果这里面不加错误提示，可以进行多个中奖号码的比较逻辑，肯定有一个是采集错误了
			throw new BaseServiceException(issueNo + "该期彩票开奖品信息已经保存过");
		}
		String[] openCodeArray = null;
		
		if(!StringUtils.isBlank(openCode)) {
			openCodeArray = openCode.split(",");
		}else {
			throw new BaseServiceException("开奖号码不能为空");
		}
		CaiPiaoOpencode insertCaiPiaoOpenCode = new CaiPiaoOpencode();
		insertCaiPiaoOpenCode.setCaiId(String.valueOf(caipiaoid));
		insertCaiPiaoOpenCode.setCaiName(_list.get(0).getCaiName());
		insertCaiPiaoOpenCode.setOpendate(openCodeDateTime);
		insertCaiPiaoOpenCode.setIssueno(issueNo);
		insertCaiPiaoOpenCode.setCaiName(caipiaoName);
		insertCaiPiaoOpenCode.setCaiTypeId(caipiaoType);
		
		if(openCodeArray != null && openCodeArray.length > 0 && StringUtils.isNotBlank(openCodeArray[0])) {
			insertCaiPiaoOpenCode.setNumber1(openCodeArray[0]);
		}
		if(openCodeArray != null && openCodeArray.length > 1 && StringUtils.isNotBlank(openCodeArray[1])) {
			insertCaiPiaoOpenCode.setNumber2(openCodeArray[1]);	
		}
		if(openCodeArray != null && openCodeArray.length > 2 && StringUtils.isNotBlank(openCodeArray[2])) {
			insertCaiPiaoOpenCode.setNumber3(openCodeArray[2]);
		}
		if(openCodeArray != null && openCodeArray.length > 3 && StringUtils.isNotBlank(openCodeArray[3])) {
			insertCaiPiaoOpenCode.setNumber4(openCodeArray[3]);
		}
		if(openCodeArray != null && openCodeArray.length > 4 && StringUtils.isNotBlank(openCodeArray[4])) {
			insertCaiPiaoOpenCode.setNumber5(openCodeArray[4]);
		}
		if(openCodeArray != null && openCodeArray.length > 5 &&  StringUtils.isNotBlank(openCodeArray[5])) {
			insertCaiPiaoOpenCode.setNumber6(openCodeArray[5]);
		}
		if(openCodeArray != null && openCodeArray.length > 6 && StringUtils.isNotBlank(openCodeArray[6])) {
			insertCaiPiaoOpenCode.setNumber7(openCodeArray[6]);
		}
		if(openCodeArray != null && openCodeArray.length > 7 && StringUtils.isNotBlank(openCodeArray[7])) {
			insertCaiPiaoOpenCode.setNumber8(openCodeArray[7]);
		}
		insertCaiPiaoOpenCode.setExtend1(String.valueOf(insertCaiPiaoOpenCode.getOpendate().getTime()));
		/*************** 组织推送内容向客户端发起推送，将开奖号码相关信息推送到该彩种的所有客户端  **************************************************************************************************************************************************************/
				
		JSONObject messageVo = JSONObject.parseObject(JSONObject.toJSON(insertCaiPiaoOpenCode).toString());
		try {
			CEvenyDayOpenTime q = new CEvenyDayOpenTime();
			q.setCaiId(caipiaoid);
			CEvenyDayOpenTime nextOpenTime =  evenyDayOpenTimeService.getCEvenyDayOpenTime(q);
			
			if(nextOpenTime != null) {
				messageVo.put("nextOpenCodeTime", String.valueOf(nextOpenTime.getOpenDate().getTime()));
				messageVo.put("nextIssueNo", nextOpenTime.getIssueno());
			}
			EntityHeader header = new EntityHeader(2);
			PushEntity<JSONObject> entity = new PushEntity<JSONObject>();
			entity.setEntitiyHeader(header);
			entity.setData(messageVo);
			socketService.pushMessage(String.valueOf(caipiaoid), entity);
		}catch(Exception e) {
			getLOGGER().error("推送开奖号码出现错误 {}", e);
			throw new BaseServiceException("推送开奖号码出现错误");
		}
		caiPiaoOpencodeService.add(insertCaiPiaoOpenCode, false);
	}
	
	@Transactional
	public void commitCaiPiao(String openCode,String source,String issueNo,String commit_time,String cai_id) {
		/***************/
		if(StringUtils.isBlank(issueNo)) {
			throw new BaseServiceException("提交开奖号码错误, 缺少开奖期数");
		}
		CaiPiao _cp = new CaiPiao();
		if(StringUtils.isNotBlank(cai_id))_cp.setCaiId(Integer.parseInt(cai_id));
		List<CaiPiao> _list = caiPiaoService.queryAll(_cp);
		if(CollectionUtils.isEmpty(_list)) {
			throw new BaseServiceException("该彩票种类在cai_piao表中不存在，cai_id : " + cai_id  +  "或者该地区没有发行该彩种");
		}
		
		if(_list.size() > 1) {
			throw new BaseServiceException("该彩票种类在cai_piao表中存在多条记录 cai_id = " + cai_id);
		}
		
		//提交上来的期号大于8位，且前两位是20则截取
		if(StringUtils.isNotBlank(issueNo)   && issueNo.length() > 9) {
			String _fix = StringUtil.substring(issueNo, 0,2);
			if(StringUtil.equals(_fix, "20")) {
				issueNo = StringUtil.substring(issueNo, 2,issueNo.length()); //去掉前两位20
			}
		}
		EvenyDayOpenTime queryEvenyDayOpenTime = new EvenyDayOpenTime();
		queryEvenyDayOpenTime.setCaiId(Long.valueOf(cai_id));
		queryEvenyDayOpenTime.setIssueno(issueNo);
		List<EvenyDayOpenTime> evenyDayOpenTimeList = evenyDayOpenTimeService.queryAll(queryEvenyDayOpenTime);
		if(CollectionUtils.isEmpty(evenyDayOpenTimeList)) {
			throw new BaseServiceException("该cai_id : " +cai_id+" , 对应的该期号 : "+ issueNo +"  在 eveny_day_open_time 表中没有记录,请联系系统管理员进行维护");
		}
		
		if(evenyDayOpenTimeList.size() > 1) {
			throw new BaseServiceException("该cai_id : " +cai_id+" , 对应的该期号 : "+ issueNo +"  在 eveny_day_open_time 表中存在多条记录,请联系系统管理员进行维护");
		}
		
		String caipiaoOpenTimeStr = DateTimeUtil.getDate(evenyDayOpenTimeList.get(0).getOpenDate(), DateTimeUtil.FORMAT_LONGTIME);
		Date openCodeDateTime;
		try {
			openCodeDateTime = DateTimeUtil.getDateByString(caipiaoOpenTimeStr, "yyyy-MM-dd HH:mm:ss");
		} catch (ParseException e) {
			getLOGGER().error("日期格式转换出错  {}" , e);
			throw new BaseServiceException("开奖日期 " + caipiaoOpenTimeStr + "  格式转换出错");
		}
		long   caipiaoid = _list.get(0).getCaiId().longValue();
		String caipiaoName = _list.get(0).getCaiName();
		String caipiaoType = _list.get(0).getCaiTypeId();
		String typeId = _list.get(0).getCaiTypeId();
		CaiPiaoOpencode queryCaiPiaoOpencode = new CaiPiaoOpencode();
		
		queryCaiPiaoOpencode.setIssueno(issueNo);
		queryCaiPiaoOpencode.setCaiTypeId(String.valueOf(typeId));
		queryCaiPiaoOpencode.setCaiId(String.valueOf(caipiaoid));
		List<CaiPiaoOpencode> _caiPiaoOpenCodeList = caiPiaoOpencodeService.queryAll(queryCaiPiaoOpencode);
		if(_caiPiaoOpenCodeList != null && _caiPiaoOpenCodeList.size() > 0) {
			CaiPiaoOpencode _opencode = _caiPiaoOpenCodeList.get(0);
			//比对
			String _cai_id = _opencode.getCaiId();
			String _issue = _opencode.getIssueno();
			
			String _code = "";
			
			if(StringUtils.isNotBlank(_opencode.getNumber1())) {
				_code += (_opencode.getNumber1() + ",");
			}
			if(StringUtils.isNotBlank(_opencode.getNumber2())) {
				_code += (_opencode.getNumber2() + ",");
			}
			if(StringUtils.isNotBlank(_opencode.getNumber3())) {
				_code += (_opencode.getNumber3() + ",");
			}
			if(StringUtils.isNotBlank(_opencode.getNumber4())) {
				_code += (_opencode.getNumber4() + ",");
			}
			if(StringUtils.isNotBlank(_opencode.getNumber5())) {
				_code += (_opencode.getNumber5() + ",");
			}
			if(StringUtils.isNotBlank(_opencode.getNumber6())) {
				_code += (_opencode.getNumber6() + ",");
			}
			if(StringUtils.isNotBlank(_opencode.getNumber7())) {
				_code += (_opencode.getNumber7() + ",");
			}
			if(StringUtils.isNotBlank(_opencode.getNumber8())) {
				_code += (_opencode.getNumber8() + ",");
			}
			
			if(StringUtils.isNotBlank(_code)) {
				_code = StringUtils.substring(_code, 0, _code.length() - 1);
			}
			
			if(StringUtils.equals(_cai_id,  cai_id) && StringUtils.equals(_issue , issueNo)) {
				if(!StringUtils.equals(_code, openCode)) {//存在错误
					String msg = "caiId:" + cai_id + " , 彩票名称:"  + caipiaoName  +  "  期号:" + _issue + " 目前存储开奖号码: " + _code  + "和渠道 " + source + " 的开奖号码:" + openCode + "存在差异,请到后台确认!" ;

					CaiPiaoErrorCode queryCaiPiaoErrorCode = new CaiPiaoErrorCode();
					queryCaiPiaoErrorCode.setCaiId(cai_id);
					queryCaiPiaoErrorCode.setIssue(_issue);
					List<CaiPiaoErrorCode> caiPiaoErrorCodeList = caiPiaoErrorCodeService.queryAll(queryCaiPiaoErrorCode);
					if(CollectionUtils.isEmpty(caiPiaoErrorCodeList)) {
						String groupId = UUIDUtils.newUUID();
						CaiPiaoErrorCode c1 = new CaiPiaoErrorCode();
						c1.setCaiId(cai_id);
						c1.setIssue(_issue);
						c1.setChannel("当前存储");
						c1.setIsCorrect(CommonStr.FALSE);
						c1.setOpenCode(_code);
						c1.setGroupId(groupId);
						caiPiaoErrorCodeService.add(c1, false);
						
						CaiPiaoErrorCode c2 = new CaiPiaoErrorCode();
						c2.setCaiId(cai_id);
						c2.setIssue(_issue);
						c2.setChannel(source);
						c2.setIsCorrect(CommonStr.FALSE);
						c2.setOpenCode(openCode);
						c2.setGroupId(groupId);
						caiPiaoErrorCodeService.add(c2, false);
					}else {
						CaiPiaoErrorCode c2 = new CaiPiaoErrorCode();
						c2.setCaiId(cai_id);
						c2.setIssue(_issue);
						c2.setChannel(source);
						c2.setIsCorrect(CommonStr.FALSE);
						c2.setOpenCode(openCode);
						c2.setGroupId(caiPiaoErrorCodeList.get(0).getGroupId());
						caiPiaoErrorCodeService.add(c2, false);						
					}
					//邮件通知
					try {
						SysRestrictionsConfig config = sysRestrictionsConfigService.getSysRestrictionsConfig("sysnoticemail");
						
						if(config == null) {
							throw new Exception("未配置socket服务器相关信息,请从数据进行配置!");
						}
						
						
						Mail mail = new Mail();
						mail.setReceive(config.getName());
						mail.setSubject("开奖号码错误提醒邮件");
						mail.setMsg(msg);
						mailService.asynchronousSendMail(mail);
					} catch (Exception e) {
						getLOGGER().error("{},{}",e.getMessage(),e);
					}
					//邮件通知结束
				}
			}
			return;
			//如果这里面不加错误提示，可以进行多个中奖号码的比较逻辑，肯定有一个是采集错误了
			//throw new BaseServiceException(issueNo + "该期彩票开奖品信息已经保存过");
		}
		String[] openCodeArray = null;
		
		if(!StringUtils.isBlank(openCode)) {
			openCodeArray = openCode.split(",");
		}else {
			throw new BaseServiceException("开奖号码不能为空");
		}
		CaiPiaoOpencode insertCaiPiaoOpenCode = new CaiPiaoOpencode();
		insertCaiPiaoOpenCode.setCaiId(String.valueOf(caipiaoid));
		insertCaiPiaoOpenCode.setCaiName(_list.get(0).getCaiName());
		insertCaiPiaoOpenCode.setOpendate(openCodeDateTime);
		insertCaiPiaoOpenCode.setIssueno(issueNo);
		insertCaiPiaoOpenCode.setCaiName(caipiaoName);
		insertCaiPiaoOpenCode.setCaiTypeId(caipiaoType);
		
		if(openCodeArray != null && openCodeArray.length > 0 && StringUtils.isNotBlank(openCodeArray[0])) {
			if(StringUtil.isNumeric(openCodeArray[0])) {
				insertCaiPiaoOpenCode.setNumber1(openCodeArray[0]);
			}else {
				throw new BaseServiceException("开奖号码首位:" + openCodeArray[0] + " 必须为数字.");
			}
			
		}
		if(openCodeArray != null && openCodeArray.length > 1 && StringUtils.isNotBlank(openCodeArray[1])) {
			insertCaiPiaoOpenCode.setNumber2(openCodeArray[1]);	
		}
		if(openCodeArray != null && openCodeArray.length > 2 && StringUtils.isNotBlank(openCodeArray[2])) {
			insertCaiPiaoOpenCode.setNumber3(openCodeArray[2]);
		}
		if(openCodeArray != null && openCodeArray.length > 3 && StringUtils.isNotBlank(openCodeArray[3])) {
			insertCaiPiaoOpenCode.setNumber4(openCodeArray[3]);
		}
		if(openCodeArray != null && openCodeArray.length > 4 && StringUtils.isNotBlank(openCodeArray[4])) {
			insertCaiPiaoOpenCode.setNumber5(openCodeArray[4]);
		}
		if(openCodeArray != null && openCodeArray.length > 5 &&  StringUtils.isNotBlank(openCodeArray[5])) {
			insertCaiPiaoOpenCode.setNumber6(openCodeArray[5]);
		}
		if(openCodeArray != null && openCodeArray.length > 6 && StringUtils.isNotBlank(openCodeArray[6])) {
			insertCaiPiaoOpenCode.setNumber7(openCodeArray[6]);
		}
		if(openCodeArray != null && openCodeArray.length > 7 && StringUtils.isNotBlank(openCodeArray[7])) {
			insertCaiPiaoOpenCode.setNumber8(openCodeArray[7]);
		}
		insertCaiPiaoOpenCode.setExtend1(String.valueOf(insertCaiPiaoOpenCode.getOpendate().getTime()));
		/*************** 组织推送内容向客户端发起推送，将开奖号码相关信息推送到该彩种的所有客户端  **************************************************************************************************************************************************************/
				
		JSONObject messageVo = JSONObject.parseObject(JSONObject.toJSON(insertCaiPiaoOpenCode).toString());
		try {
			///////////////////////// new version get next open code info
			CEvenyDayOpenTime q = new CEvenyDayOpenTime();
			q.setCaiId(caipiaoid);
			CEvenyDayOpenTime nextOpenTime =  evenyDayOpenTimeService.getCEvenyDayOpenTime(q);
			
			if(nextOpenTime != null) {
				messageVo.put("nextOpenCodeTime", String.valueOf(nextOpenTime.getOpenDate().getTime()));
				messageVo.put("nextIssueNo", nextOpenTime.getIssueno());
			}
			EntityHeader header = new EntityHeader(PushType.push_open_code.getCode());
			PushEntity<JSONObject> entity = new PushEntity<JSONObject>();
			entity.setEntitiyHeader(header);
			entity.setData(messageVo);
			socketService.pushMessage(String.valueOf(caipiaoid), entity);
		}catch(Exception e) {
			getLOGGER().error("推送开奖号码出现错误 {}", e);
			throw new BaseServiceException("推送开奖号码出现错误");
		}
		caiPiaoOpencodeService.add(insertCaiPiaoOpenCode, false);
		
		

		//异步处理模拟投注的计算
		final String temp_issueNo = issueNo;
		executorService.execute(new Runnable() {
			@Override
			public void run() {
				try {
					caiPiaoSimulationPlanService.matchOpenCode(caipiaoid, Integer.parseInt(caipiaoType), temp_issueNo, openCode);
				} catch (Exception e) {
					getLOGGER().error("模拟投注开奖计算错误错误, 详情: {} " , e.getMessage() , e );
				}
			}
		});
		
		executorService.execute(new Runnable() {
			@Override
			public void run() {
				try {
					//caiPiaoMissCodeListService.matchingMissCode(caipiaoid, openCode, temp_issueNo);
					
					caiPiaoMissCodeListService.computeOpenCodeMissValue(String.valueOf(caipiaoid), openCode, temp_issueNo);
					
					
				} catch (Exception e) {
					getLOGGER().error("匹配中奖号码遗漏错误, 详情: {} " , e.getMessage() , e );
				}
			}
		});
	}
	
	public ResponseEntity<?> update_push_opencode(CaiPiaoOpencode openCode) {
		List<CaiPiaoOpencode> list = caiPiaoOpencodeService.queryAll(openCode);
		if(CollectionUtils.isEmpty(list)) {
			return new ResponseEntity<>(new ResponseBaseModel(29002,openCode.getIssueno() + "," + openCode.getCaiId() + " : 该期彩票还未开奖，查不到已存在的开奖信息"), HttpStatus.OK);
		}
		if(list.size() > 1) {
			return new ResponseEntity<>(new ResponseBaseModel(29002, openCode.getIssueno() + "," + openCode.getCaiId() + " : 该期开奖号码在开奖号码表中存在多条记录，请联系管理员"), HttpStatus.OK);
		}
		
		try {
			
			EntityHeader header = new EntityHeader(PushType.update_open_code.getCode());
			PushEntity<CaiPiaoOpencode> entity = new PushEntity<CaiPiaoOpencode>();
			entity.setEntitiyHeader(header);
			entity.setData(list.get(0));
			socketService.pushMessage(String.valueOf(openCode.getCaiId()), entity);
			return new ResponseEntity<>(new ResponseResultModel<String>("更新推送开奖号码成功!"),HttpStatus.OK);
		}catch (Exception e) {
			return new ResponseEntity<>(new ResponseBaseModel(29002,"更新推送开奖号码错误!"), HttpStatus.OK);
		}
		
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}
